#!/usr/bin/env python
# coding:utf-8

"""
打印异常的方法
"""

print '---------------------------------------------------------------------------'
"""
[1] 只能打印: 异常信息
"""
try:
    x = 1/0
except Exception, e:
    print e
print '---------------------------------------------------------------------------'
"""
[2] 可以打印: 异常信息、异常文件、所在代码等
"""
try:
    x = 1/0
except Exception, e:
    import traceback
    traceback.print_exc()
print '---------------------------------------------------------------------------'
"""
[3] 可以打印: 异常信息、异常文件、所在代码等 (返回字符串)
"""
try:
    x = 1/0
except Exception, e:
    import traceback
    tb = traceback.format_exc()
    print tb
print '---------------------------------------------------------------------------'
